<template>
    <Layout>
        <div v-if="statisticPage">
            <Form ref="form1" :model="form1" :label-width="120">
                <Row class="query-form">
                    <Col span="8">
                        <FormItem label="二级集团：">
                            <two-level-org org-code class="query-form-el" v-model="form1.twoLevelOrgCode" />
                        </FormItem>
                    </Col>
                    <Col span='8'>
                        <FormItem label='所属单位：' prop="companyId">
                            <Input v-model='form1.companyName' class="query-form-el"></Input>
                        </FormItem>
                    </Col>

                    <Col span="8">
                        <!--<Button @click="switchQuery(true)" class="ivu-btn-switch" type="text"  >展开∨</Button>-->
                        <Button @click="reset" class="ivu-btn-reset" style="margin-left: 2px">重置</Button>
                        <Button class="ivu-btn-query" icon="md-search" @click="query()">查询</Button>
                    </Col>
                </Row>
                <Row v-if="isResult===1" class="query-form">
                    <Col span="24">
                        <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
                        <Button size="large" class="ivu-btn-add" icon="md-download" @click="downloadDescriptionExcel">导出模板</Button>
                        <Button size="large" class="ivu-btn-add" icon="md-cloud-upload" @click="beachUpload">批量导入</Button>
                        <!--<Button size="large" class="ivu-btn-add" icon="md-cloud-download" :loading="buttonLoading" @click="exportForm">导出</Button>-->
                    </Col>
                </Row>
            </Form>
        </div>
        <div v-else>
            <Form ref="form1" :model="form1" :label-width="120">
                <Row class="query-form">
                    <Col span='8'>
                        <FormItem label='所属单位：' prop="companyId">
                            <cascader-dom ref='queryOrgCascader' @setOrgInfo='setCompanyId0'
                                          @setOrgname='(data)=>{form1.companyName=data}' :orgTree="true"
                                          :currentOrgId="currentUser.companyId" class="query-form-el"
                                          :setCurrentName="{label:form1.companyName,value:form1.companyId}">
                            </cascader-dom>
                        </FormItem>
                    </Col>
                    <Col span="8">
                        <FormItem label="人员名称：">
                            <Input type="text" class="query-form-el" v-model="form1.driverName"/>
                        </FormItem>
                    </Col>
                    <Col span="8" v-if="!switchFlag">
                        <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text"  >展开∨</Button>
                        <Button @click="reset" class="ivu-btn-reset" style="margin-left: 2px">重置</Button>
                        <Button class="ivu-btn-query" icon="md-search" @click="query()">查询</Button>
                    </Col>
                    <Col span="8" v-else>
                        <FormItem label="作业类型：">
                            <Input class="query-form-el" type="text" v-model="form1.workType"></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row  v-show="switchFlag" class="query-form">
                    <Col span="8">
                        <FormItem label="发证日期：">
                            <DatePicker class="query-form-el" v-model="form1.certificateDate" format="yyyy-MM-dd"
                                        type="daterange" placement="bottom-start" placeholder="请选择查询时间段"
                                        @on-change="(date) => onSelectFieldQueryDateRange(date,'certificateDate')"></DatePicker>
                        </FormItem>
                    </Col>
                    <Col span="8">
                        <FormItem label="复审日期：">
                            <DatePicker class="query-form-el" v-model="form1.reviewDate" format="yyyy-MM-dd"
                                        type="daterange" placement="bottom-end" placeholder="请选择查询时间段"
                                        @on-change="(date) => onSelectFieldQueryDateRange(date,'reviewDate')"></DatePicker>
                        </FormItem>
                    </Col>
                    <Col span="8">
                        <FormItem label="项目名称：">
                            <Input class="query-form-el" type="text" v-model="form1.projectName"></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row  v-show="switchFlag" class="query-form">
                    <Col span="8" offset="16">
                        <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
                        <Button @click="reset" class="ivu-btn-reset" >重置</Button>
                        <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                    </Col>
                </Row>
                <Row class="query-form">
                    <Col span="24">
                         <span v-if="isResult===1">
                              <Button size="large" class="ivu-btn-add" icon="md-add" @click="addInfo">新增</Button>
                         </span>
                         <download-button :api="exportUrl" :queryForm="form1" />
                        <!-- <Button size="large" class="ivu-btn-add" icon="md-cloud-download" :loading="buttonLoading" @click="saCarInfo">导出</Button> -->
                        <Button size="large" class="ivu-btn-add" icon="md-arrow-back"  @click="goback">返回</Button>
                    </Col>
                </Row>
            </Form>
            <!--<Table ref='table' :height="tableHeight" :loading="loading" size="small" class="table" no-data-text="没有查询到相关数据!"-->
                   <!--highlight-row stripe border :columns="columns1" width="100%" :data="dataTable" :row-class-name="rowClassName">-->
            <!--</Table>-->
        </div>
        <Table ref='table' :height="tableHeight" :loading="loading" size="small" class="table" no-data-text="没有查询到相关数据!"
            @on-sort-change="sortChange"
            highlight-row stripe border :columns="statisticPage?columns2:columns1" width="100%" :data="dataTable" :row-class-name="rowClassName">
        </Table>
        <Row style="margin-right:10px;">
            <Col span="24">
                <Page :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange"
                      style="float: right" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
                      show-total show-sizer show-elevator/>
            </Col>
        </Row>

        <Modal :transfer=false v-model="model1" :width=981 :title="add?'特种设备人员新增':'特种设备人员修改'" @on-cancel="onCancel">
            <div>
                <Form style="margin-left: 10px" ref='InputData' :show-message="false" :model="InputData" :rules="ruleCustom" label-position="top">
                    <Row style="line-height: 28px;">
                        <Col span='5' >
                            <FormItem label='姓名：' prop="driverName">
                                <Input v-model="InputData.driverName"/>
                            </FormItem>
                        </Col>
                        <Col span='5' offset="1">
                            <FormItem label='所属单位：' prop="companyId">
                                <cascader-dom ref='orgCascader' @setOrgInfo='setCompanyId' @setOrgname="setCompanyName" :orgTree="true"
                                              :currentOrgId="currentUser.companyId" @on-change="belongChange"
                                              :setCurrentName="{label:InputData.companyName,value:InputData.companyId}">
                                </cascader-dom>
                            </FormItem>
                        </Col>
                        <Col span='5' offset="1">
                            <FormItem label='所属部门：'>
                                <cascader-dom ref='orgCascader1' @setOrgInfo='setCompanyId1' @setOrgname="setCompanyName1" :orgTree="true"
                                              :currentOrgId="InputData.companyId"
                                              :setCurrentName="{label:InputData.departmentName,value:InputData.departmentId}">
                                </cascader-dom>
                            </FormItem>
                        </Col>
                        <Col span='5' offset="1">
                            <FormItem label='岗位：'>
                                <Input v-model="InputData.station" />
                            </FormItem>
                        </Col>
                    </Row>
                    <Row style="line-height: 28px;">
                        <Col span='5' >
                            <FormItem label='身份证：' prop='colour'>
                                <Input  v-model="InputData.colour" />
                            </FormItem>
                        </Col>
                        <!--<Col span='5' offset="1">-->
                            <!--<FormItem label='性别：' prop="brand">-->
                                <!--<Select class="query-form-el" filterable v-model="InputData.brand"  >-->
                                    <!--<Option v-for="item in brandList" :value="item.value" :key="item.value">{{ item.name }}</Option>-->
                                <!--</Select>-->
                            <!--</FormItem>-->
                        <!--</Col>-->
                        <Col span='5' offset="1">
                            <FormItem label='作业类型：'>
                                <Input v-model="InputData.workType" show-word-limit :maxlength="32"/>
                            </FormItem>
                        </Col>
                        <Col span='5' offset="1">
                            <FormItem label='项目名称（代号）：' prop="projectName">
                                <Input v-model="InputData.projectName" show-word-limit :maxlength="100"/>
                            </FormItem>
                        </Col>
                        <Col span='5' offset="1">
                            <FormItem label='证书编号：' prop="certificateNo">
                                <Input v-model="InputData.certificateNo" show-word-limit :maxlength="32"/>
                            </FormItem>
                        </Col>
                    </Row>
                    <Row style="line-height: 28px;">
                        <Col span='5'>
                            <FormItem label='发证机关：' prop="certificationAuthority">
                                <Input v-model="InputData.certificationAuthority" show-word-limit :maxlength="50"/>
                            </FormItem>
                        </Col>
                        <Col span='5' offset="1">
                            <FormItem label='发证日期：' prop="certificateDate">
                                <Date-picker type="date" placeholder="选择日期" v-model="InputData.certificateDate"></Date-picker>
                            </FormItem>
                        </Col>
                        <Col span='5'offset="1" >
                            <FormItem label='有效期：' prop="validityTerm">
                                <Date-picker type="date" placeholder="选择日期" v-model="InputData.validityTerm"></Date-picker>
                            </FormItem>
                        </Col>
                        <Col span='5' offset="1">
                            <FormItem label='复审日期：' prop="reviewDate">
                                <Date-picker type="date" placeholder="选择日期" v-model="InputData.reviewDate"></Date-picker>
                            </FormItem>
                        </Col>
                    </Row>
                    <Row style="line-height: 28px;">
                        <Col span='23' >
                            <FormItem label='复审情况：' prop="review">
                                <Input v-model="InputData.review" show-word-limit :maxlength="500"/>
                            </FormItem>
                        </Col>
                    </Row>
                    <!--<Row>-->
                        <!--<Col span="23">-->
                            <!--<div class="query-form">-->
                                <!--<Button class="ivu-btn-add" icon="md-add" @click="addItemInfo()">新增项目</Button>-->
                            <!--</div>-->
                            <!--<Table :max-height="250" :loading="loading" size="small" class="table" no-data-text="没有查询到相关数据!"-->
                                   <!--highlight-row stripe border :columns="columns3" width="100%" :data="evaluateItem">-->
                            <!--</Table>-->
                        <!--</Col>-->
                    <!--</Row>-->
                </Form>
            </div>
            <div slot="footer">
                <Button class='ivu-btn-save' :loading="buttonLoading" @click="submit('InputData')">确定</Button>
                <Button class='ivu-btn-cancel' @click="onCancel">取消</Button>
            </div>
        </Modal>

        <Modal :transfer=false v-model="model3" :width=1000  title="特种人员详情"
               @on-cancel="onCancel">
            <Form style="margin-left: 10px" :model="InputData" label-position="top">
                <Row style="line-height: 42px;">
                    <Col span='7' >
                        <span>姓名：{{InputData.driverName}}</span>
                    </Col>
                    <!--<Col span='7' offset="1">-->
                        <!--<span>性别：{{InputData.brand === '0'? '男':'女'}}</span>-->
                    <!--</Col>-->
                    <Col span='7' offset="1">
                        <span>身份证：{{InputData.colour}}</span>
                    </Col>
                    <Col span='7' offset="1">
                        <span>所属单位：{{InputData.companyName}}</span>
                    </Col>
                </Row>
                <Row class="detail-background-clor" style="line-height: 42px;">
                    <Col span='7'>
                        <span>所属部门：{{InputData.departmentName}}</span>
                    </Col>
                    <Col span='7'  offset="1">
                        <span>岗位：{{InputData.station}}</span>
                    </Col>
                    <Col span='7' offset="1">
                        <span>作业类型：{{InputData.workType}}</span>
                    </Col>
                </Row>
                <Row style="line-height: 42px;">
                    <Col span='7'>
                        <span>项目名称：{{InputItemData.projectName}}</span>
                    </Col>
                    <Col span='7' offset="1">
                        <span>证书编号：{{InputData.certificateNo}}</span>
                    </Col>
                    <Col span='7' offset="1">
                        <span>发证机关：{{InputData.certificationAuthority}}</span>
                    </Col>
                </Row>
                <Row class="detail-background-clor" style="line-height: 42px;">
                    <Col span='7'>
                        <span>发证日期：{{certificateDate1}}</span>
                    </Col>
                    <Col span='7'  offset="1">
                        <span>有效期：{{validityTerm}}</span>
                    </Col>
                    <Col span='7' offset="1">
                        <span>复审日期：{{reviewDate1}}</span>
                    </Col>
                </Row>
                <Row style="line-height: 42px;">
                    <Col span='23' >
                        <span>复审情况：{{InputData.review}}</span>
                    </Col>
                </Row>
                <!--<Row>-->
                    <!--<Col span='23' style="margin-top: 10px;margin-bottom: 10px">-->
                        <!--<Table max-height="300" class="table"  :loading="loading" size="small" no-data-text="没有查询到相关数据!"-->
                               <!--highlight-row stripe border :columns="columns10" width="100%" :data="evaluateItem">-->
                        <!--</Table>-->
                    <!--</Col>-->
                <!--</Row>-->
            </Form>
            <div slot="footer">
                <Button class='ivu-btn-save' @click="onCancel">关闭</Button>
            </div>
        </Modal>

        <Modal :transfer=false v-model="model6" :width=700 title="特种设备操作人员导入" @on-cancel="cancelMap">
            <Form  ref="map" :show-message="false" :model="map" :rules="mapRuleCustom" label-position="top">
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="23">
                        <FormItem label='企业名称：' prop='companyId'>
                            <cascader-dom ref='orgCascader2' @setOrgInfo='setCompanyId2' @setOrgname="setCompanyName2"
                                          :orgTree="true" :currentOrgId="currentUser.companyId">
                            </cascader-dom>
                        </FormItem>
                    </Col>
                </Row>
                <Row type="flex" justify="space-around" class="code-row-bg">
                    <Col span="23">
                        <FormItem  label="特种设备操作人员excel文件" prop="file">
                            <div>
                                <Upload ref="upload1"
                                        :before-upload="handleUpload "
                                        :format="['xlsx', 'xls']"
                                        accept=".xlsx, .xls"
                                        :max-size="10240"
                                        type="drag"
                                        :action="uploadUrl">
                                    <div style="padding: 10px">
                                        <Icon type="ios-cloud-upload" size="45" style="color: #3399ff"></Icon>
                                        <p>点击将文件拖拽到这里上传</p>
                                        <span style="font-size:8px;color: #797a64">仅支持上传单个excel </span>
                                    </div>
                                </Upload>
                            </div>
                            <div v-if="fileTrue">
                                <a>{{ map.file.name }}</a>
                                <Button type="text" icon="md-trash" @click="map.file = {},fileTrue = false" style="margin-left: 5px;margin-bottom: 3px"/>
                            </div>
                        </FormItem>
                    </Col>
                </Row>
            </Form>
            <div slot="footer">
                <Button type="primary" class='ivu-btn-save' :disabled="uploadDissabled" @click="submitFile('map')">确定</Button>
                <Button type="primary" class='ivu-btn-cancel' @click="cancelMap">取消</Button>
            </div>
        </Modal>

        <Modal title="导入详情" v-model="logInfoModel" :transfer=false :mask-closable="false">
            <Row type="flex" justify="space-around" class="code-row-bg">
                <Col span="23">
                    <div v-html="logInfo"></div>
                </Col>
            </Row>
            <div slot="footer">
                <Button type="primary" class='ivu-btn-cancel' @click="logInfoModel=false,logInfo=null">关闭</Button>
            </div>
        </Modal>

        <!--<Modal :transfer=false v-model="model4" :width=700  :title="addItem?'项目新增':'项目修改'"-->
               <!--@on-cancel="model4=false;InputItemData={}">-->
            <!--<div>-->
                <!--<Form ref='InputItemData' :model="InputItemData" :rules="ruleCustom1" label-position="top">-->
                    <!--<Row style="line-height: 42px;">-->
                        <!--<Col span='7'>-->
                            <!--<FormItem label='项目名称：' prop="projectName">-->
                                <!--<Input v-model="InputItemData.projectName" />-->
                            <!--</FormItem>-->
                        <!--</Col>-->
                        <!--<Col span='7' offset="1">-->
                            <!--<FormItem label='批准日期：' prop="approvalDate">-->
                                <!--<Date-picker type="date" style="width: 100%" v-model="InputItemData.approvalDate"/>-->
                            <!--</FormItem>-->
                        <!--</Col>-->
                        <!--<Col span='7' offset="1">-->
                            <!--<FormItem label='有效日期：' prop="effectiveDate">-->
                                <!--<Date-picker type="date" style="width: 100%" v-model="InputItemData.effectiveDate"/>-->
                            <!--</FormItem>-->
                        <!--</Col>-->
                        <!--<Col span='23'>-->
                            <!--<FormItem label='备注：' prop="remarks">-->
                                <!--<Input v-model="InputItemData.remarks" type="textarea"-->
                                       <!--:autosize="{minRows:2,maxRows:5}"/>-->
                            <!--</FormItem>-->
                        <!--</Col>-->

                    <!--</Row>-->
                <!--</Form>-->
            <!--</div>-->
            <!--<div slot="footer">-->
                <!--<Button class='ivu-btn-save' :loading="buttonLoading" @click="submitItem('InputItemData')">确定</Button>-->
                <!--<Button class='ivu-btn-cancel' @click="model4=false;InputItemData={}">取消</Button>-->
            <!--</div>-->
        <!--</Modal>-->

        <!--<Modal :transfer=false v-model="model5"  :width=600 :title="'项目详情'"-->
               <!--@on-cancel="model5=false" >-->
            <!--<Form class="modal-view-detail" :model="InputItemData" label-position="top" >-->
                <!--<Row style="line-height: 42px;">-->
                    <!--<Col span='7'>-->
                        <!--<span>项目名称：{{InputItemData.projectName}}</span>-->
                    <!--</Col>-->
                    <!--<Col span='7' offset="1">-->
                        <!--<span>批准日期：{{approvalDate}}</span>-->
                    <!--</Col>-->
                    <!--<Col span='7' offset="1">-->
                        <!--<span>有效日期：{{effectiveDate}}</span>-->
                    <!--</Col>-->
                <!--</Row>-->
                <!--<Row class="detail-background-clor" style="line-height: 42px;">-->
                    <!--<Col span='23'>-->
                        <!--<span>备注：{{InputItemData.remarks}}</span>-->
                    <!--</Col>-->
                <!--</Row>-->
            <!--</Form>-->
            <!--<div slot="footer">-->
                <!--<Button class='ivu-btn-save' @click="model5=false">关闭</Button>-->
            <!--</div>-->
        <!--</Modal>-->

    </Layout>
</template>

<script>
import {Api} from '../../../../api/index.js'
import {sessionStorage} from '../../../../common/cacheUtils.js';
import pageCommonFunction from '@/components/pageCommonFunction.js'

var cascaderDom = () => import('@/components/cascader-dom.vue');

export default {
        components: {cascaderDom},
        data() {
            return {
                statisticPage: true,
                certificateDate1:'',
                reviewDate1:'',
                switchFlag:false,
                certificateDate:['',''],
                reviewDate:['',''],
                brandList:[
                    {name:'男', value:'0',},
                    {name:'女', value:'1',}
                ],
                addItem:false,
                InputItemDate:{},
                model4:false,
                dataTable:[],
                tableHeight: '',loading: false,
                validityTerm:'',
                form1: {
                    agreementName: '',
                    contractorName: '',
                },
                pageSizeArray: [10, 20, 50],
                pagedata: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1,
                },
                model5:false,
                ruleCustom: {
                    driverName: [{message: '  ', required: true, trigger: 'blue'}],
                    // brand: [{message: '  ', required: true, trigger: 'blur'}],
                    colour: [
											{ required: true, message: '请填写身份证号', trigger: 'change'},
											{ validator: this.idCardValidator,  trigger: 'change' }
										],
                    companyId: [{message: '  ', required: true, trigger: 'change'}],
                    // departmentId: [{message: '  ', required: true, trigger: 'change'}],
                    // workType: [{message: '  ', required: true, trigger: 'blur'}],
                    // station: [{message: '  ', required: true, trigger: 'blur'}],
                    projectName: [{message: '  ', required: true, trigger: 'blue'}],
                    certificateNo: [{message: '  ', required: true, trigger: 'blur'}],
                    certificationAuthority: [{message: '  ', required: true, trigger: 'blur'}],
                    certcard: [{message: '  ', required: true, trigger: 'blur'}],
                    validityTerm: [{
                        validator: (rule, value, callback) => {
                            if (value == null || value == ''|| value == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    // review: [{message: '  ', required: true, trigger: 'blur'}],
                    certificateDate: [{
                        validator: (rule, value, callback) => {
                            if (value == null || value == ''|| value == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                    reviewDate: [{
                        validator: (rule, value, callback) => {
                            if (value == null || value == ''|| value == undefined) {
                                callback(' ')
                            } else {
                                callback()
                            }
                        },
                        required: true,
                        trigger: 'change'
                    }],
                },
                // ruleCustom1: {
                //     projectName: [{message: '  ', required: true, trigger: 'blue'}],
                //     approvalDate: [{
                //         validator: (rule, value, callback) => {
                //             if (value == null || value == ''|| value == undefined) {
                //                 callback(' ')
                //             } else {
                //                 callback()
                //             }
                //         },
                //         required: true,
                //         trigger: 'change'
                //     }],
                //     effectiveDate: [{
                //         validator: (rule, value, callback) => {
                //             if (value == null || value == ''|| value == undefined) {
                //                 callback(' ')
                //             } else {
                //                 callback()
                //             }
                //         },
                //         required: true,
                //         trigger: 'change'
                //     }],
                // },
                evaluateItem: [],
                // columns3: [
                //     {type: 'index', title: '序号', width: 80, align: 'center',},
                //     {minWidth: 100, title: '项目名称', align: 'center', key: 'projectName',},
                //     {minWidth: 120, title: '批准日期', align: 'center', key: 'approvalDate',
                //         render: (h, params) => {return h('div', [(this.formatDate(new Date(params.row.approvalDate), 'yyyy-MM-dd'))]);}},
                //     {minWidth: 150, title: '有效日期', align: 'center', key: 'effectiveDate',
                //         render: (h, params) => {return h('div', [(this.formatDate(new Date(params.row.effectiveDate), 'yyyy-MM-dd'))]);}},
                //     {minWidth: 150, title: '备注', align: 'center', tooltip:true, key: 'remarks'},
                //     {
                //         title: '操作',
                //         key: 'action',
                //         fixed: 'right',
                //         width: 160,
                //         align: 'center',
                //         render: (h, params) => {
                //             return h('div', [
                //                 h('A', {
                //                     props: {
                //                         type: 'primary',
                //                         size: 'small'
                //                     },
                //                     style: {
                //                         fontSize: '14px',
                //                     },
                //                     on: {
                //                         click: () => {
                //                             this.InputItemData = params.row;
                //                             let effectiveDate = new Date(params.row.effectiveDate);
                //                             this.effectiveDate = effectiveDate.getFullYear() + '-' + (effectiveDate.getMonth() + 1) + '-' + effectiveDate.getDate()
                //                             let approvalDate = new Date(params.row.approvalDate);
                //                             this.approvalDate = approvalDate.getFullYear() + '-' + (approvalDate.getMonth() + 1) + '-' + approvalDate.getDate()
                //                             this.model5 = true;
                //                         }
                //                     }
                //                 }, '详情'),
                //                 h('Divider', {
                //                     props: {
                //                         type: 'vertical',
                //                     }
                //                 }, ''),
                //                 h('A', {
                //                     props: {
                //                         type: 'primary',
                //                         size: 'small'
                //                     },
                //                     style: {
                //                         fontSize: '14px',
                //                     },
                //                     on: {
                //                         click: () => {
                //                             this.InputItemData = params.row;
                //                             this.model4 = true;
                //                             this.addItem = false;
                //                             this.index = params.index;
                //                         }
                //                     }
                //                 }, '修改'),
                //                 h('Divider', {
                //                     props: {
                //                         type: 'vertical',
                //                     }
                //                 }, ''),
                //                 h('A', {
                //                     props: {
                //                         type: 'error',
                //                         size: 'small'
                //                     },
                //                     style: {
                //                         fontSize: '14px',
                //                         color: 'red',
                //                     },
                //                     on: {
                //                         click: () => {
                //                             this.evaluateItem.splice(params.index,1);
                //                         }
                //                     }
                //                 }, '删除')
                //             ]);
                //         }
                //     }
                // ],
                index:null,
                currentUser: JSON.parse(sessionStorage('userId').get('userId')),
                columns1: [
                    {type: 'index', title: '序号', width: 65, fixed: 'left', align: 'center',},
                    {title: '姓名', align: 'center', fixed: 'left', key: 'driverName', width: 80,},
                    {title: '所属单位', align: 'center', key: 'companyName', minWidth: 160,},
                    {title: '所属部门', align: 'center', key: 'departmentName', minWidth: 160,},
                    // {title: '性别', align: 'center', key: 'brand', width: 65,
                    //     render: (h, params) => {return h('div', [(params.row.brand === '0'?'男':'女')])}},
                    {title: '身份证', align: 'center', key: 'colour', minWidth: 180,},
                    {title: '作业类型', align: 'center', key: 'workType', width: 160,},
                    {title: '岗位', align: 'center', key: 'station', width: 120,},
                    {minWidth: 160, title: '项目名称（代号）', align: 'center', key: 'projectName',tooltip:true},
                    {title: '证书编号', align: 'center', key: 'certificateNo', minWidth: 180,},
                    {title: '发证机关', align: 'center', key: 'certificationAuthority', minWidth: 180,},
                    {title: '发证日期',sortable: "custom",  align: 'center', key: 'certificateDate', width: 120,
                        render: (h, params) => {return h('div', [(this.formatDate(new Date(params.row.certificateDate), 'yyyy-MM-dd'))]);}},
                    {title: '有效期',sortable: "custom",  align: 'center', key: 'validityTerm', width: 120,
                        render: (h, params) => {return h('div', [(this.formatDate(new Date(params.row.validityTerm), 'yyyy-MM-dd'))]);}},
                    {title: '复审日期',sortable: "custom",  align: 'center', key: 'reviewDate', width: 120,
                        render: (h, params) => {return h('div', [(this.formatDate(new Date(params.row.reviewDate), 'yyyy-MM-dd'))]);}},
                    {title: '复审情况', align: 'center', key: 'review', width: 120,},
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        width: 180,
                        align: 'center',
                        render: (h, params) => {
                            let flag = this.currentUser.loginId === this.Common.admin || this.currentUser.userId === params.row.createUsrId  || this.currentUser.userRole.find(obj => obj.roleId == '73b38b37dff64392ba0ee7dd579bf293') != undefined
                                ||sessionStorage('userId').getObject('userId').userBeHandedOver.find(obj => obj == params.row.createUserId) != undefined;
                            if (this.isResult ===1){
                                return h('div', [
                                    h('A', {
                                        props: {
                                            type: 'primary',
                                            size: 'small'
                                        },
                                        style: {
                                            fontSize: '14px',
                                        },
                                        on: {
                                            click: () => {
                                                this.InputData = params.row;
                                                this.certificateDate1 = this.formatDate(new Date(this.InputData.certificateDate), 'yyyy-MM-dd');

                                                this.reviewDate1 = this.formatDate(new Date(this.InputData.reviewDate), 'yyyy-MM-dd');
                                                this.validityTerm = this.formatDate(new Date(this.InputData.validityTerm), 'yyyy-MM-dd');
                                                this.evaluateItem = params.row.saSemWorkerProjects;
                                                this.model3 = true;
                                            }
                                        }
                                    }, '详情'),
                                    h('Divider', {
                                        props: {
                                            type: 'vertical',
                                        }
                                    }, ''),
                                    h('A', {
                                        props: {
                                            type: 'primary',
                                            size: 'small'
                                        },
                                        style: {
                                            fontSize: '14px',
                                            color: flag? '': '#d0d0d0',
                                            pointerEvents:flag ? '': 'none',
                                        },
                                        on: {
                                            click: () => {
                                                this.evaluateItem = params.row.saSemWorkerProjects;
                                                this.InputData = params.row;
                                                this.model1 = true;
                                                this.add = false;
                                            }
                                        }
                                    }, '修改'),
                                    h('Divider', {
                                        props: {
                                            type: 'vertical',
                                        }
                                    }, ''),
                                    h('A', {
                                        props: {
                                            type: 'error',
                                            size: 'small'
                                        },
                                        style: {
                                            fontSize: '14px',
                                            color: flag? 'red': '#d0d0d0',
                                            pointerEvents:flag ? '': 'none',
                                        },
                                        on: {
                                            click: () => {
                                                this.$Modal.confirm({
                                                    title: '数据删除',
                                                    content: '<p>确定删除该条信息</p>',
                                                    okText: '确认',
                                                    onOk: () => {
                                                        this.deleteData(params.row);
                                                    },
                                                    cancelText: '取消'
                                                });
                                            }
                                        }
                                    }, '删除')
                                ]);
                            }else{
                                return h('div', [
                                    h('A', {
                                        props: {
                                            type: 'primary',
                                            size: 'small'
                                        },
                                        style: {
                                            fontSize: '14px',
                                        },
                                        on: {
                                            click: () => {
                                                this.InputData = {...params.row};
                                                this.certificateDate1 = this.formatDate(new Date(this.InputData.certificateDate), 'yyyy-MM-dd');

                                                this.reviewDate1 = this.formatDate(new Date(this.InputData.reviewDate), 'yyyy-MM-dd');
                                                this.validityTerm = this.formatDate(new Date(this.InputData.validityTerm), 'yyyy-MM-dd');
                                                this.evaluateItem = params.row.saSemWorkerProjects;
                                                this.model3 = true;
                                            }
                                        }
                                    }, '详情'),
                                    h('Divider', {
                                        props: {
                                            type: 'vertical',
                                        }
                                    }, ''),
                                    h('A', {
                                        props: {type: 'primary', size: 'small'},
                                        style: {
                                            fontSize: '14px',
                                            color: flag? '': '#d0d0d0',
                                            pointerEvents:flag ? '': 'none',
                                        },
                                        on: {
                                            click: () => {
                                                this.evaluateItem = params.row.saSemWorkerProjects;
                                                this.InputData = {...params.row};
                                                this.model1 = true;
                                                this.add = false;
                                            }
                                        }
                                    }, '修改'),
                                ]);
                            }

                        }
                    }
                ],
                columns2: [
                    {title: '序号', width: 65, fixed: 'left', align: 'center', render: this.indexColumnsRender},
                    {key: 'companyName', title: '企业名称', align: 'center', minWidth: 200},
                    {key: 'str', title: '待检人员数量', align: 'center', minWidth: 160,
					 renderHeader:(h, params) => {
						 return h('span',this.isResult ==1?'人员数量':'待检人员数量')
					 }},
                    {key: 'belongOrgName', title: '二级集团', align: 'center', minWidth: 150},
                    {
                        title: '操作',
                        key: 'action',
                        fixed: 'right',
                        width: 80,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('A', {
                                    props: {type: 'primary', size: 'small'},
                                    style: {
                                        fontSize: '14px',
                                    },
                                    on: {
                                        click: () => {
                                            this.statisticPage = false
                                            // this.form1.companyName = params.row.companyName
                                            this.form1.companyName = params.row.orgName
                                            this.form1.companyId = params.row.companyId
                                            this.query()
                                        }
                                    }
                                }, '详情'),
                            ])
                        }
                    }
                ],
                updateParam:null,
                effectiveDate:'',
                approvalDate:'',
                add: false,
                model1: false,
                model3: false,
                contractTermDate1:'',
                evaluationPeriodDate1:'',
                exportUrl: Api.exportsaSemWorkerInfo,
                fileUrl: Api.interestedPartiesUserFile,
                uploadUrl:Api.uploadSemWorkerInfo,
                InputData: {},
                buttonLoading: false,
                InputItemData:{},
                uploadList: [],

                pageModel2: {
                    total: 0,
                    pageSize: 10,
                    currentPage: 1,
                    contractorName: ''
                },
                contractor: [],
                model2: false,
                // InputData1: {},

                fileTrue:false,
                uploadDissabled:false,
                map:{},
                mapRuleCustom: {
                    companyId: [{required: true, message: ' ', trigger: 'change'}],
                    categoryId: [{required: true, message: ' ', trigger: 'change'}],
                    file: [{
                        validator: (rule, value, callback) => {
                            if (this.map.file) {
                                callback()
                            } else {
                                callback(' ')
                            }
                        },
                        required: true,
                        message: ' ',
                        trigger: 'change'
                    }]
                },
                model6:false,
                logInfoModel:false,
                logInfo:null
            }
        },
        mounted() {
            this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
            console.log(this.currentUser);
            this.query()
        },
        computed: {
            isResult() {
                return this.$route.name ==='semWorkerInfo'? 1 : 2 //SaSemWorkerInfoPending 1、查询列表  2、查询待审列表
            },
            columns10() {
                const columns = [...this.columns3];
                const columns10=[]
                columns.forEach(item=>{
                   if (item.title != '操作'){
                       columns10.push(item)
                   }
                });
                return columns10
            },
        },
        methods: {
            ...pageCommonFunction,
            sortChange(data) {
                if (data.order === 'asc'||data.order ==='desc') {
                    let order = data.key
                    this.form1.dynamicSort = order +' '+ data.order
                    this.query()
                }
            },
            setCompanyId0(data) {
                this.form1.companyId = data[data.length - 1];
            },
            setCompanyId(data){
                this.InputData.companyId = data[data.length - 1];
            },
            belongChange(value) {
                this.$set(this.InputData,'companyId',value.value)
                this.$set(this.InputData,'companyName',value.label)
                this.InputData.departmentId = null
                this.InputData.departmentName = null
                this.$refs.orgCascader.resetCurrentOrg();
                this.show = false;
                setTimeout(() => {
                    this.show = true
                }, 0)
            },
            setCompanyName(data){
                this.InputData.companyName = data;
            },
            setCompanyId1(data){
                this.InputData.departmentId = data[data.length - 1];
            },
            setCompanyName1(data){
                this.InputData.departmentName = data;
            },
            switchQuery(flag,){
                this.switchFlag = flag;
                if(!this.switchFlag){
                    this.tableHeight = this.tableHeight + 88;
                }else{
                    this.tableHeight = this.tableHeight - 88;
                }
            },
            submitItem(name){
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        if (this.addItem){
                            // this.evaluateItem.push(this.InputItemData);
							this.evaluateItem.unshift(this.InputItemData);
                            this.model4 = false;
                        } else{
                            let index = this.index;
                            this.evaluateItem[index] = this.InputItemData;
                            this.model4 = false;
                        }

                    }else{
                        this.$Message.error('请填报完整!');
                    }
                })
            },
            addItemInfo(){
                this.addItem = true;
                this.InputItemData = {};
                this.model4 = true
            },
            // baocun() {
            //     this.InputData.contractorName = this.InputData1.contractorName
            //     this.InputData.contractorId = this.InputData1.contractorId
            //     this.model2 = false
            // },
            danxuan(row, index) {
                this.InputData.contractorId = row.contractorId
                this.InputData.contractorName = row.contractorName
                this.model2 = false
                this.model1 = true
            },

            selectContractor() {
                this.model2 = true
                this.contractor = []
                let data = {
                    startPage: this.pageModel2.currentPage,
                    size: this.pageModel2.pageSize,
                    contractorName: this.pageModel2.contractorName
                }
                data = Object.assign(data);
                let url = Api.interestedPartiesAccountList
                this.$http.get(url, {params: data}).then((res) => {
                    console.log(res.data);
                    this.contractor = res.data.data.data;
                    this.pageModel2.total = res.data.data.totalSize;
                }).catch(e => {
                    this.$Message.error("数据获取失败")
                })
            },

            downloadFile(perfId, file) {
                let url = this.fileUrl + '/file/' + file.id;
                this.$http.get(url, {
                    responseType: 'blob'      //告诉服务器我们需要的响应格式
                }).then((res) => {
                    console.log(res)
                    const aLink = document.createElement("a");
                    let blob = new Blob([res.data], {
                        type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
                    });
                    aLink.href = URL.createObjectURL(blob)
                    aLink.download = file.fileName //标题
                    aLink.click()
                    document.body.appendChild(aLink)
                })
            },
            remove1(id) {
                console.log(id)
                let url = this.fileUrl + '/file/' + id;
                this.$http.delete(url).then((res) => {
                    this.getFiles()
                })
            },
            formatDate(date, fmt) {
                if (/(y+)/.test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
                }
                let o = {
                    'M+': date.getMonth() + 1,
                    'd+': date.getDate(),
                    'h+': date.getHours(),
                    'm+': date.getMinutes(),
                    's+': date.getSeconds()
                };
                for (let k in o) {
                    if (new RegExp(`(${k})`).test(fmt)) {
                        let str = o[k] + '';
                        fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
                    }
                }
                return fmt;
            },
            padLeftZero(str) {
                return ('00' + str).substr(str.length);
            },
            beforeUpload(file) {
                console.log(this.uploadList)
                let formData = new FormData();
                formData.append("files", file); // 文件对象
                let url = this.fileUrl + '/' + this.InputData.perfId + '/files/agreementFile'
                this.$http.post(url, formData).then((res) => {
                    if (res.data.result == "success") {
                        this.$Message.info("文件上传成功")
                        this.getFiles();
                    }
                })
                return false
            },
            getFiles() {
                let url = this.fileUrl + '/' + this.InputData.perfId + '/files/agreementFile'
                this.$http.get(url).then((res) => {
                    if (res.data.result == "success") {
                        console.log(res.data)
                        this.uploadList = res.data.data
                    }
                })
            },



            downloadDescriptionExcel(){
                this.$http.get(Api.templateDownload+'9', {
                    responseType: 'blob'      //告诉服务器我们需要的响应格式
                }).then((res) => {
                    const aLink = document.createElement("a");
                    let blob = new Blob([res.data], {
                        type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
                    });
                    aLink.href = URL.createObjectURL(blob)
                    aLink.download = "特种设备操作人员模板.xlsx" //标题
                    aLink.click()
                    document.body.appendChild(aLink)
                })
            },
            submitFile(map){
                this.$refs[map].validate((valid) => {
                    if (valid) {
                        this.uploadDissabled = true
                        let formData = new FormData();
                        formData.append("file", this.map.file);
                        formData.append("companyId", this.map.companyId);
                        formData.append("createUserId", this.currentUser.userId);
                        formData.append("createOrgId", this.currentUser.orgInfo.orgId);
                        this.$http.post(this.uploadUrl, formData).then((res) => {
                            this.uploadDissabled = false
                            if (res.data.status == "200") {
                                // this.$Message.success("特种设备导入成功! 导入详情请查看控制台");
                                this.logInfoModel = true
                                this.logInfo = res.data.data
                                this.query()
                            } else {
                                this.$Message.error(res.data.msg);
                            }
                            this.map={}
                            this.fileTrue = false
                            this.model6=false
                        }).catch(e => {
                            console.log(e);
                            this.model6=false
                            this.map={}
                            this.uploadDissabled = false
                            this.$Message.error("导入失败！请检查导入文档的格式是否正确");
                        })
                    } else {
                        this.$Message.error('请填报完整!');
                    }
                })

            },
            handleUpload (file) {
                this.map.file = file;
                this.fileTrue = true
                return false;
            },
            cancelMap(){
                this.model6 = false
                this.fileTrue = false
                this.map ={}
                this.$refs.orgCascader2.resetCurrentOrg();
            },
            beachUpload(){
                this.model6 = true
                this.fileTrue = false
                this.map ={}
                this.$refs.orgCascader2.resetCurrentOrg();
            },
            setCompanyId2(data) {
                if (data && data instanceof Array && data.length > 0) {
                    this.$set(this.map, 'companyId', data[data.length - 1])
                    // if(this.$refs.dialogForm) this.$refs.dialogForm.validateField('companyId')
                }
            },
            setCompanyName2(data) {
                if (data) {
                    this.map.companyName = data;
                    // this.$refs.dialogForm1.validateField('companyId')
                }
            },



            onCancel() {
                this.InputData = {};
                this.evaluateItem = [];
                this.model1 = false;
                this.model3 = false;
                this.uploadList = [];
                this.query()
            },
            submit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        this.buttonLoading=true
                        this.InputData.saSemWorkerProjects = this.evaluateItem;
                        if (this.add) {
                            let url = Api.saSemWorkerInfoSave;
                            this.InputData.createOrgId = sessionStorage('userId').getObject('userId').orgInfo.orgId;
                            this.InputData.createUsrId = sessionStorage('userId').getObject('userId').userId;
                            this.$http.post(url, this.InputData).then((res) => {
                                this.$Message.success('成功');
                                // this.uploadFile();
                                this.buttonLoading = false
                                this.model1 = false
                                this.query()
                            }).catch(e => {
                                this.$Message.error('请求失败');
                            })
                        } else {
                            let url = Api.saSemWorkerInfoUpdate;
                            this.InputData.createUsrId = sessionStorage('userId').getObject('userId').userId
                            this.InputData.updateOrgId = sessionStorage('userId').getObject('userId').orgInfo.orgId
                            this.$http.post(url, this.InputData).then((res) => {
                                this.$Message.success('成功');
                                // this.uploadFile();
                                this.buttonLoading = false
                                this.model1 = false
                                this.query()
                            }).catch(e => {
                                this.$Message.error('请求失败');
                            })
                        }
                    } else {
                        this.$Message.error('请填报完整!');
                    }
                })

            },

            deleteData(row) {
                let url = Api.saSemWorkerInfoDelete + '/' + row.driverId;
                this.$http.delete(url).then((res) => {
                    this.$Message.success('成功');
                    this.query()
                }).catch(e => {
                    this.$Message.error("数据获取失败")
                })
            },
            addInfo() {
                this.add = true;
                this.InputData = {};
                this.evaluateItem = [];
                this.model1 = true;
            },
            onSelectFieldQueryDateRange(data, filed) {
                if (data[0] === "" || data[1] === "") {
                    this.form1[filed + 'Start'] = null;
                    this.form1[filed + 'End'] = null;
                } else {
                    this.form1[filed + 'Start'] = data[0] + ' 00:00:00';
                    this.form1[filed + 'End'] = data[1] + ' 23:59:59';
                }
            },
            exportForm(){
                this.dataToQuery = {...this.form1}
                this.exportFormSubmit()
            },
            goback(){
                if (this.switchFlag) {
                    this.switchQuery(false)
                }
                this.statisticPage = true
                this.form1 = {}
                this.query()
            },
            query() {
                this.loading = true ;
                this.form1.listType = this.isResult
								this.form1.statistics = 'statistics' 
                let data = {
                    startPage: this.pagedata.currentPage,
                    size: this.pagedata.pageSize,
                    conditions: this.form1
                };
                // data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));
                let url =this.statisticPage ? Api.saSemWorkerInfoQuery+'/page':Api.saSemWorkerInfoQuery
                this.$http.post(url, data).then((res) => {
                    console.log(res.data);
                    this.dataTable = res.data.data.data;
                    this.pagedata.total = res.data.data.totalSize;
                    this.loading = false;
                }).catch(e => {
                    this.$Message.error("数据获取失败")
                    this.loading = false;
                })
            },
            reset() {
                this.form1 = {}
                this.pageModel2.currentPage = 1;
                this.pageModel2.contractorName = ''
                if (!this.statisticPage) {
                    this.$refs.queryOrgCascader.resetCurrentOrg();
                }
				this.query();
            },
            pageChange1(pageNum) {
                this.pageModel2.currentPage = pageNum;
                this.query();
            },
            pageSizeChange1(pageSize) {
                this.pageModel2.pageSize = pageSize;
                this.query();
            },
            pageChange(pageNum) {
                this.pagedata.currentPage = pageNum;
                this.query();
            },
            pageSizeChange(pageSize) {
                this.pagedata.pageSize = pageSize;
                this.query();
            },
            rowClassName(row,index){
                var date = this.formatDate(new Date(),'yyyy-MM-dd')
                if(row.reviewDate < date){
                    return 'table-row-red';
                }
            },
            get_uuid() {
                let s = [];
                let hexDigits = "0123456789abcdef";
                for (let i = 0; i < 36; i++) {
                    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
                }
                s[14] = "4";
                s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
                s[8] = s[13] = s[18] = s[23] = "-";

                let uuid = s.join("");
                let reg = new RegExp("-", "g");
                let a = uuid.replace(reg, "");
                console.log(a);
                return a;
            },
        },
        watch:{
            "model1":function(qw,er){
                if(qw && this.model1){
                    setTimeout(()=>{
                        this.$refs.orgCascader.setCurrentOrg();
                        this.$refs.orgCascader1.setCurrentOrg();
                    },100)
                }else{
                    this.$refs.orgCascader.setCurrentOrg();
                    this.$refs.orgCascader1.setCurrentOrg();
                }
            },
            '$route.name': function () {
                this.statisticPage = true
                // if (this.isResult === 2) {
                //     this.tableHeight = this.tableHeight + 25;
                // } else {
                //     this.tableHeight = this.tableHeight - 25;
                // }
                this.reset()
            }
        },
    }
</script>

<style scoped>
    @import '../../../../index.css';
    .ivu-table-tbody .table-row-red td{
        background-color: #fedede !important;
    }
</style>
